<?php
$plugin->load_plugin_lang();

$tpl = new Template_plugin('course/plugin/quizz_qcm2/templates/index.tpl');

if($_POST)
{

	$response = retrieve(POST, 'response', '');
	if($response != '')
	{
		$Sql->query_inject("INSERT INTO phpboost_plugin_quizz_qcm2_correction (response)
		VALUES ('".$response."')", __LINE__, __FILE__);
		$last_id_correction = $Sql->insert_id("SELECT MAX(id) FROM phpboost_plugin_quizz_qcm2_correction");
		$result_saving = $plugin->save_score(null, $module_lp->get_module_id(), $_SERVER['PHP_SELF'], $last_id_correction);
		if(!$result_saving)
		{
			$Sql->query_inject("DELETE FROM phpboost_plugin_quizz_qcm2_correction WHERE id=$last_id_correction", __LINE__, __FILE__);
			$tpl->assign_vars(array(
				'EXERCISE_DONE' => true,
			));
		}
		else
		{
			redirect($currentLink.'save');
		}
	}
	
}




$tpl->assign_vars(array(
	'FORM_ACTION' => $currentLink,
));

$tpl->parse();
?>